package train.time0623;

public class No4 {
	int[][] chessboard =  new int[8][8];
	public static void main(String[] args) {
		No4 app = new No4();
		app.inQ(5, 5);
		for (int aa = 0; aa < app.chessboard.length; aa++) {
			for (int ab = 0; ab < app.chessboard.length; ab++) {
				for (int ba = aa; ba < app.chessboard.length; ba++) {
					for (int bb = ab; bb < app.chessboard.length; bb++) {
						for (int ca = ba; ca < app.chessboard.length; ca++) {
							for (int cb = bb; cb < app.chessboard.length; cb++) {
								for (int da = ca; da < app.chessboard.length; da++) {
									for (int db = cb; db < app.chessboard.length; db++) {
										for (int ea = da; ea < app.chessboard.length; ea++) {
											for (int eb = db; eb < app.chessboard.length; eb++) {
												if(
													(aa==ba&ab==bb)||
													(ba==ca&bb==cb)||
													(ca==da&cb==db)||
													(da==ea&db==eb)){
													continue;
												}
												app.inQ(aa, ab);
												app.inQ(ba, bb);
												app.inQ(ca, cb);
												app.inQ(da, db);
												app.inQ(ea, eb);
												boolean flag = false;
												for (int i = 0; i < app.chessboard.length; i++) {
													for (int j = 0; j < app.chessboard.length; j++) {
														if(app.chessboard[i][j]==0){
															flag = true;
															break;
														}
													}
													if(flag){
														break;
													}
												}
												if(!flag){
													app.chessboard[aa][ab]=-1;
													app.chessboard[ba][bb]=-1;
													app.chessboard[ca][cb]=-1;
													app.chessboard[da][db]=-1;
													app.chessboard[ea][eb]=-1;
													for (int i = 0; i < app.chessboard.length; i++) {
														for (int j = 0; j < app.chessboard.length; j++) {
															System.out
																	.print(app.chessboard[i][j]+"\t");
														}
														System.out
																.println();
													}
													System.out
															.println("--------------------------------");
												}
												app.chessboard = new int[8][8];
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	private void inQ(int a,int b) {
		for (int i = 0; i < chessboard.length; i++) {
			if(b+(i-a)>=0&&b+(i-a)<chessboard.length){
				chessboard[i][b+(i-a)]=1;
			}
			if(b+(a-i)>=0&&b+(a-i)<chessboard.length){
				chessboard[i][b+(a-i)]=1;
			}
			chessboard[a][i]=1;
			chessboard[i][b]=1;
		}
//		for (int i = 0; i < chessboard.length; i++) {
//			for (int j = 0; j < chessboard.length; j++) {
//				System.out.print(chessboard[i][j]+"  ");
//			}
//			System.out.println();
//		}
		
	}

}
